{% extends 'base.html' %}

{% block title %}为用户分配角色 - {{ user_.username }} - Django RBAC 项目{% endblock %}

{% block content %}
    <div class="container mx-auto px-4 py-8">
        <h1 class="text-2xl font-bold mb-6">为用户 "{{ user_.username }}" 分配角色</h1>
        <form method="post" class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
            {% csrf_token %}
            <div class="mb-4">
                <label class="block text-gray-700 text-sm font-bold mb-2" for="{{ form.role.id_for_label }}">
                    选择角色
                </label>
                {{ form.role }}
            </div>
            <div class="flex items-center justify-between">
                <button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline"
                        type="submit">
                    分配角色
                </button>
                <a href="{% url 'user_list' %}"
                   class="inline-block align-baseline font-bold text-sm text-blue-500 hover:text-blue-800">
                    返回用户列表
                </a>
            </div>
        </form>
        <!-- 当前角色列表 -->
        <div class="mt-8 bg-white shadow overflow-hidden sm:rounded-lg">
            <div class="px-4 py-5 sm:px-6">
                <h3 class="text-lg leading-6 font-medium text-gray-900">
                    当前角色
                </h3>
            </div>
            <div class="border-t border-gray-200">
                <ul class="divide-y divide-gray-200">
                    {% for user_role in user_roles %}
                        <li class="px-4 py-4 sm:px-6">
                            <div class="flex items-center justify-between">
                                <div class="text-sm font-medium text-gray-900">
                                    {{ user_role.role.name }}
                                </div>
                                <div class="flex items-center">
{#                                    <div class="text-sm text-gray-500 mr-4">#}
{#                                        分配时间: {{ assign_time|date:"Y-m-d H:i" }}#}
{#                                    </div>#}
                                    <form method="post"
                                          action="{% url 'unassign_role_from_user' user_.id user_role.role.id %}">
                                        {% csrf_token %}
                                        <button type="submit"
                                                class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline">
                                            取消分配
                                        </button>
                                    </form>
                                </div>
                            </div>
                        </li>
                    {% empty %}
                        <li class="px-4 py-4 sm:px-6 text-sm text-gray-500">
                            该用户当前没有分配角色
                        </li>
                    {% endfor %}
                </ul>
            </div>
        </div>

    </div>
{% endblock %}

